package org.example.examsystem.service;


import org.example.examsystem.entity.Teacher;
import org.example.examsystem.mapper.TeacherMapper;
import org.example.examsystem.service.TeacherService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class TeacherServiceImpl implements TeacherService {

    private final TeacherMapper teacherMapper;

    public TeacherServiceImpl(TeacherMapper teacherMapper) {
        this.teacherMapper = teacherMapper;
    }

    @Override
    public Page<Teacher> getTeachers(Pageable pageable) {
        int offset = (int) pageable.getOffset();
        int limit = pageable.getPageSize();
        List<Teacher> teachers = teacherMapper.getTeachers(offset, limit);
        int total = teacherMapper.getTotalTeachers();
        return new PageImpl<>(teachers, pageable, total);
    }

    @Override
    public int addTeacher(Teacher teacher) {
        return teacherMapper.addTeacher(teacher);
    }

    @Override
    public int updateTeacher(Teacher teacher) {
        return teacherMapper.updateTeacher(teacher);
    }

    @Override
    public int deleteTeacher(int userid) {
        return teacherMapper.deleteTeacher(userid);
    }

    @Override
    public int batchDeleteTeachers(List<Integer> ids) {
        return teacherMapper.batchDeleteTeachers(ids);
    }
    @Override
    public Optional<Teacher> findTeacherById(int userid) {
        return teacherMapper.findTeacherById(userid);
    }
}